package graphic.tests;

import graphic.GameView;
import graphic.render.Render2D;
import graphic.render.StandardRender;

import javax.swing.JFrame;

/**
 * 
 * @author Jan
 *
 */
public class FPSAverage extends GameView{

	private static final long serialVersionUID = 8631295392800682319L;
	private long lastTime;
	private long nextTime;
	private long delta;
	private long val = 0;
	private long iterations = 0;
	
	public FPSAverage(Render2D render) {
		super(render);
		lastTime = System.currentTimeMillis();
	}
	
	@Override
	public void tick(Render2D renderScreen) {
		nextTime = System.currentTimeMillis();
		delta = nextTime-lastTime;
		val += delta;
		iterations++;
		
		System.out.println("[delay medio: "+val/iterations+" || delay = "+delta+"]");
		lastTime = nextTime;
	}
	
	public static void main(String[] args) {
		JFrame frame = new JFrame();
		
		//Da qui avvieremo il gioco.
		GameView game= new FPSAverage( new StandardRender() );
		
		frame.add(game);
		frame.pack();
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setVisible(true);
		frame.setResizable(false);
		frame.setLocationRelativeTo(null);
		game.start();
	}
}
